local extension = Package("heroes_com1")
extension.extensionName = "evolution"
--extension.game_modes_whitelist = {"brokenroyal_mode"}

local EV = require "packages/evolution/EV"
local U = require "packages/utility/utility"


Fk:loadTranslationTable{
  ["heroes_com1"] = "旧约角色01",
  ["com"] = "旧约",
}
local xiaozhi = General(extension, "com__xiaozhi", "com", 3)
local ev__shoufu = fk.CreateTriggerSkill{
  name = "ev__shoufu",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name) == 0 then
      local ids = {}
      local room = player.room
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          if move.moveReason == fk.ReasonDiscard and move.from then
            for _, info in ipairs(move.moveInfo) do
              if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and room:getCardArea(info.cardId) == Card.DiscardPile then
                table.insertIfNeed(ids, info.cardId)
              end
            end
          end
        end
      end
      ids = U.moveCardsHoldingAreaCheck(room, ids)
      if #ids > 0 then
        self.cost_data = ids
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = table.simpleClone(self.cost_data)
    local cards, choice = U.askforChooseCardsAndChoice(player, ids, {"OK"}, self.name,
    "#ev__shoufu-choose", {"drawcard"}, 1, 1)
    if choice == "drawcard" then
      player:drawCards(1, self.name)
    else
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, self.name)
    end
    if player:getHandcardNum() > player.maxHp then
      room:askForDiscard(player, 1, 1, false, self.name, false)
    end
  end,
}

xiaozhi:addSkill(ev__shoufu)
Fk:loadTranslationTable{
  ["com__xiaozhi"] = "小智",
  ["designer:com__xiaozhi"] = "辰木",
  ["ev__shoufu"] = "收服",
  [":ev__shoufu"] = "回合技，当一名角色的牌因弃置而置入弃牌堆后，你可选择一项：1.摸一张牌；2.获得其中的一张牌。选择完毕后，若你的手牌数大于体力上限，则你弃置一张手牌。",
  ["#ev__shoufu-choose"] = "收服：你可以获得其中一张牌，或选择摸一张牌",
  ["drawcard"] = "摸牌",
}

local xiaoxia = General(extension, "com__xiaoxia", "com", 3, 3, General.Female)
local ev__dishui = fk.CreateViewAsSkill{
  name = "ev__dishui",
  pattern = "slash,jink",
  interaction = function()
    local names = {}
    for _, name in ipairs({"ev__slash","ev__jink"}) do
      local card = Fk:cloneCard(name)
      if (Fk.currentResponsePattern == nil and Self:canUse(card)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card)) then
        if Self.phase ~= Player.NotActive then
          table.insertIfNeed(names, "ev__slash")
        else
          table.insertIfNeed(names, "ev__jink")
        end
      end
    end
    if #names == 0 then return end
    return U.CardNameBox {choices = names}
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    card:addSubcard(cards[1])
    return card
  end,
}

xiaoxia:addSkill(ev__dishui)

local ev__juanliu = fk.CreateTriggerSkill{
  name = "ev__juanliu",
  events = {fk.CardUsing, fk.CardResponding},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card.type == Card.TypeBasic and data.card.color == Card.Black then
      local room = player.room
      local events = {}
      if event == fk.CardUsing then
        events = room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e)
        local use = e.data[1]
        return use.from == player.id and use.card.type == Card.TypeBasic and use.card.color == Card.Black end, Player.HistoryTurn)
      else
        events = room.logic:getEventsOfScope(GameEvent.RespondCard, 2, function(e)
        local response = e.data[1]
        return response.from == player.id and response.card.type == Card.TypeBasic and response.card.color == Card.Black end, Player.HistoryTurn)
      end
      return #events == 1
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      player:drawCards(1, self.name)
    else
      player.room:moveCardTo(data.card, Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true)
    end
  end,
}

xiaoxia:addSkill(ev__juanliu)

Fk:loadTranslationTable{
    ["com__xiaoxia"] = "小霞",
    ["designer:com__xiaoxia"] = "木因",
    ["ev__dishui"] = "抵水",
    [":ev__dishui"] = "你的回合内/外，你可将一张黑色手牌当【杀】/【闪】使用或打出。",
    ["ev__juanliu"] = "涓流",
    [":ev__juanliu"] = "当你于当前回合内首次<font color=\"#6495ED\">使用</font>/<font color=\"#D2042D\">打出</font>黑色基础牌时，你可<font color=\"#6495ED\">摸一张牌</font>/<font color=\"#D2042D\">获得此牌</font>。",
  }

local guliu = General(extension, "com__guliu", "com", 3)

local ev__yandong = fk.CreateTriggerSkill{
  name = "ev__yandong",
  anim_type = "offensive",
  events ={fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.map(table.filter(player.room:getOtherPlayers(player), function(p)
      return player:getHandcardNum() <= p:getHandcardNum() end), Util.IdMapper)
      local to = player.room:askForChoosePlayers(player, targets, 1, 1, "#ev__yandong-choose", self.name, true)
      if #to > 0 then
        self.cost_data = to[1]
        return true
      end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local cid = room:askForCardChosen(player, to, "he", self.name)
    if cid then
      room:moveCardTo(cid, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
      if Fk:getCardById(cid).color == Card.Black then
        room:useVirtualCard("ev_ice__slash", nil, player, to, self.name, false)
      end
    end
  end,
}

local ev__linghan = fk.CreateTriggerSkill{
  name = "ev__linghan",
  events = {fk.TargetConfirmed},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      return data.card.color == Card.Black and data.card.trueName == "slash"
    end
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForDiscard(player, 1, 1, true, self.name, true, ".", "#ev__linghan-discard:::"..data.card:toLogString())
    return #card > 0
  end,
  on_use = function(self, event, target, player, data)
    --table.insertIfNeed(data.nullifiedTargets, player.id)
    EV.nullifiedCard(data, data.card, player)
  end,
}

guliu:addSkill(ev__yandong)
guliu:addSkill(ev__linghan)

Fk:loadTranslationTable{
  ["com__guliu"] = "古柳",
  ["designer:com__guliu"] = "木因",
  ["ev__yandong"] = "严冬",
  [":ev__yandong"] = "结束阶段，你可弃置手牌数不小于你的一名角色的一张牌；若此牌为黑色牌，你可视为对其使用冰【杀】。",
  ["#ev__yandong-choose"] = "严冬：你可弃置手牌数不小于你的一名角色的一张牌",
  ["ev__linghan"] = "凌寒",
  [":ev__linghan"] = "当你成为黑色【杀】的目标后，你可弃置一张牌，令此【杀】对你无效。",
  ["#ev__linghan-discard"] = "你可弃置一张牌，令%arg对你无效",
}

local banmu = General(extension, "com__banmu", "com", 4)
local ev__handi = fk.CreateActiveSkill{
  name = "ev__handi",
  prompt = "#ev__handi",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  target_num = 0,
  card_num = 2,
  card_filter = function(self, to_select, selected)
    return #selected < 2 and Fk:getCardById(to_select).color == Card.Black
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:moveCardTo(effect.cards, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
    for _, p in ipairs(room:getOtherPlayers(player)) do
      local cardResponded = room:askForResponse(p, 'jink', nil, nil, true, nil, effect)
      if cardResponded then
        room:responseCard({
          from = p.id,
          card = cardResponded,
          responseToEvent = effect,
        })
      else
        room:damage({
          from = player,
          to = p,
          damage = 1,
          damageType = fk.NormalDamage,
          skillName = self.name,
        })
      end
    end
  end
}

banmu:addSkill(ev__handi)

local ev__furan = fk.CreateTriggerSkill{
  name = "ev__furan",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events ={fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and player:getHandcardNum() < player:getLostHp()
  end,

  on_use = function(self, event, target, player, data)
    local n = player:getLostHp() - player:getHandcardNum()
    player:drawCards(n, self.name)
  end,
}

banmu:addSkill(ev__furan)

Fk:loadTranslationTable{
  ["com__banmu"] = "坂木",
  ["designer:com__banmu"] = "木因&zengyouyu",
  ["ev__handi"] = "撼地",
  ["#ev__handi"] = "你可以选择两张黑色牌弃置",
  [":ev__handi"] = "阶段技，你可弃置两张黑色牌，令所有其他角色各选择一项：1.打出【闪】；2.受到你造成的1点伤害。",
  ["ev__furan"] = "复燃",
  [":ev__furan"] = "锁定技，准备阶段，你将手牌补至X张（X为你已损失的体力值）。",
}

local Cirno = General(extension, "com__cirno", "com", 4, 4, General.Female)

local ev__bingjie = fk.CreateTriggerSkill{
  name = "ev__bingjie",
  frequency = Skill.Compulsory,
  anim_type = "control",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.color == Card.Black and player.phase ~= Player.NotActive
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local events = room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
      local use = e.data[1]
      return use.from == player.id end, Player.HistoryTurn)
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if player:distanceTo(p) <= #events then
        room:setPlayerMark(p, "@@ev__bingjie-turn", 1)
      end
    end
  end,
}

local ev__bingjie_effect = fk.CreateProhibitSkill{
  name = "#bingjie_effect",
  prohibit_use = function(self, player, card)
    return player:getMark("@@ev__bingjie-turn") > 0 and Fk:currentRoom():getCardArea(card) == Card.PlayerHand
  end,
  prohibit_response = function(self, player, card)
    return player:getMark("@@ev__bingjie-turn") > 0 and Fk:currentRoom():getCardArea(card) == Card.PlayerHand
  end,
}

ev__bingjie:addRelatedSkill(ev__bingjie_effect)
Cirno:addSkill(ev__bingjie)

local ev__fuhan = fk.CreateTriggerSkill{
  name = "ev__fuhan",
  events = {fk.TargetConfirmed, fk.Damaged},
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.TargetConfirmed then
        return data.card.color == Card.Black and data.card.type ~= Card.TypeEquip
      elseif event == fk.Damaged then
        return data.from
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirmed then
      if #room:askForDiscard(room:getPlayerById(data.from), 1, 1, true, self.name, true, ".|.|heart,diamond", "#ev__fuhan-discard:"..player.id) == 0 then
        EV.nullifiedCard(data, data.card, player)
      end
    elseif event == fk.Damaged then
      if #room:askForDiscard(data.from, 1, 1, true, self.name, true, ".|.|heart,diamond", "#ev__fuhan-damage") == 0 then
        room:addPlayerMark(data.from, "MinusMaxCards-turn", 2)
      end
    end
  end,
}

Cirno:addSkill(ev__fuhan)

Fk:loadTranslationTable{
  ["com__cirno"] = "琪露诺",
  ["designer:com__cirno"] = "辰木",
  ["ev__bingjie"] = "冰结",
  ["@@ev__bingjie-turn"] = "冰结",
  ["#bingjie_effect"] = "冰结",
  [":ev__bingjie"] = "锁定技，当你于回合内使用黑色牌指定目标后，你令你距离X以内的其他角色于本回合内不能使用或打出手牌(X为你于本回合内使用过的牌数)。",
  ["ev__fuhan"] = "负寒",
  [":ev__fuhan"] = "锁定技，当你<font color=\"#6495ED\">成为黑色非装备牌的目标后</font>/<font color=\"#D2042D\">受到伤害后</font>，<font color=\"#6495ED\">此牌的使用者</font>/<font color=\"#D2042D\">伤害来源</font>需弃置一张红色牌，否则<font color=\"#6495ED\">此牌对你无效</font>/<font color=\"#D2042D\">其手牌上限于当前回合内-2</font>。",
  ["#ev__fuhan-discard"] = "请弃置一张红色牌，否则此牌对%src无效",
  ["#ev__fuhan-damage"] = "请弃置一张红色牌，否则此回合手牌上限-2",
}




local Orange = General(extension, "com__orange", "com", 3, 3, General.Female)
local ev__shifu = fk.CreateTriggerSkill{
  name = "ev__shifu",
  anim_type = "support",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self.name) and player:usedSkillTimes(self.name, Player.HistoryRound) < 2 and not player:isKongcheng() then
      local targets = {}
      for _, move in ipairs(data) do
        if move.from and player.room.current and move.from ~= player.room.current.id and player.room:getPlayerById(move.from):isAlive() then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              table.insertIfNeed(targets, move.from)
            end
          end
        end
      end
      if #targets > 0 then
        self.cost_data = targets
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local targets = self.cost_data
    if table.every(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end) then
      targets:removeOne(player.id)
    end
    if #targets > 0 then
      local to = player.room:askForChoosePlayers(player, targets, 1, 1, "#ev__shifu-choose", self.name, true)
      if #to > 0 then
        self.cost_data = to[1]
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {}
    local to = self.cost_data
    local unshown = table.filter(player:getCardIds(Player.Hand), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
    if #unshown > 0 then table.insert(choices, "ev__shifu1") end
    if to and player.id ~= to and not room:getPlayerById(to).dead then table.insert(choices, "ev__shifu2::"..to) end
    if #choices > 0 then
      local choice = room:askForChoice(player, choices, self.name, "", false, {"ev__shifu1","ev__shifu2::"..to})
      if choice == "ev__shifu1" then
        EV.OpenCards(room, player, unshown, self.name)
      else
        local card = room:askForCard(player, 1, 1, false, self.name, false, ".", "ev__shifu2::"..to)
        if #card > 0 then
          room:obtainCard(to, card[1], false, fk.ReasonGive)
        end
      end
      room:getPlayerById(to):drawCards(1, self.name)
    end
  end
}

local ev__huamao = fk.CreateDistanceSkill{
  name = "ev__huamao",
  frequency = Skill.Compulsory,
  fixed_func = function(self, from, to)
    if from:hasSkill(self.name) and to:getHandcardNum() > from:getHandcardNum() then
      return 1
    end
  end,
}

local huamao_attackrange = fk.CreateAttackRangeSkill{
  name = "#wv__huamao_attackrange",
  without_func = function (self, from, to)
    return from:getHandcardNum() > to:getHandcardNum() and to:hasSkill(self.name)
  end,
}

ev__huamao:addRelatedSkill(huamao_attackrange)
Orange:addSkill(ev__shifu)
Orange:addSkill(ev__huamao)

Fk:loadTranslationTable{
  ["com__orange"] = "橙",
  ["designer:com__orange"] = "夜之礼赞+KINGDOM43+zengyouyu+南家二傻",
  ["ev__shifu"] = "式符",
  [":ev__shifu"] = "每轮限两次，当一名角色于其回合外失去牌后，你可选择一项：1.明置所有手牌；2.将一张手牌交给其。选择完毕后，其摸一张牌。",
  --["#ev__shifu"] = "你可以对%src发动【式符】",
  ["#ev__shifu-choose"] = "式符：请选择一名此次失去牌的角色",
  ["ev__shifu1"] = "明置所有手牌",
  ["ev__shifu2"] = "将一张手牌交给%dest",
  ["ev__huamao"] = "化猫",
  [":ev__huamao"] = "锁定技，你与手牌数大于你的角色的距离视为1，且视为不在其攻击范围内。",
}

local HonMeirin = General(extension, "com__honmeirin", "com", 4, 4, General.Female)

local ev__caiji = fk.CreateTriggerSkill{
  name = "ev__caiji",
  anim_type = "defensive",
  events = {fk.TargetConfirming},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self.name) and data.card.trueName == "slash" and player:inMyAttackRange(target)
  end,
  on_cost = function(self, event, target, player, data)
    local card = player.room:askForCard(player, 1, 1, false, self.name, true, ".|.|.|hand", "#ev__caiji-card")
    if #card > 0 then
      self.cost_data = card
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk:getCardById(self.cost_data[1])
    if card.color == Card.Red and card:getMark("@@shown-inhand") == 0 then
      EV.OpenCards(room, player, self.cost_data, self.name, player)
      player.room:doIndicate(target.id, { player.id })
      TargetGroup:removeTarget(data.targetGroup, target.id)
      TargetGroup:pushTargets(data.targetGroup, player.id)
    elseif card.color == Card.Black then
      room:moveCardTo(card, Card.DiscardPile, nil, fk.ReasonDiscard, self.name)
      if not target:isNude() then
      local cid = room:askForCardChosen(player, target, "he", self.name)
        if cid then
          room:moveCardTo(cid, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
        end
      end
    end
  end,
}

local ev__hujin = fk.CreateTriggerSkill{
  name = "ev__hujin",
  anim_type = "defensive",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card.trueName == "slash"
    and player:usedSkillTimes(self.name) < player:getLostHp() + 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if room.current then room:setPlayerMark(room.current , "hujin-target", 1) end
    room:setPlayerMark(player, "BypassTimesLimit", 1)
    U.askForUseVirtualCard(room, player, "ev__slash", nil, self.name)
    room:setPlayerMark(player, "BypassTimesLimit", 0)
    if room.current then room:setPlayerMark(room.current , "hujin-target", 0) end
  end,
}

local hujin_tar = fk.CreateTargetModSkill{
  name = "#ev__hujin_tar",
  bypass_distances = function(self, player, skill, card, to)
    return card and card.trueName == "slash" and card.skillName == "ev__hujin" and player:hasSkill(self.name) and to:getMark("hujin-target") > 0
  end,
}

ev__hujin:addRelatedSkill(hujin_tar)

HonMeirin:addSkill(ev__caiji)
HonMeirin:addSkill(ev__hujin)

Fk:loadTranslationTable{
  ["com__honmeirin"] = "红美铃",
  ["designer:com__honmeirin"] = "夜之礼赞",
  ["ev__caiji"] = "彩极",
  [":ev__caiji"] = "当你攻击范围内的一名角色成为【杀】的目标时，你可选择一项：1.弃置一张黑色手牌，然后弃置其一张牌；2.明置一张红色手牌，然后将此【杀】（使用者不得为你）转移给你。",
  ["#ev__caiji-card"] = "彩极：你可弃置一张黑色牌，或明置一张红色牌",
  ["ev__hujin"] = "虎劲",
  [":ev__hujin"] = "回合技（X），当你成为【杀】的目标后，你可视为使用【杀】；若目标为当前回合角色，则此【杀】无距离限制（X为你已损失的体力值+1）。",
}

local Remilia = General(extension, "com__remilia", "com", 4, 4, General.Female)

local ev__shenqiang = fk.CreateTriggerSkill{
  name = "ev__shenqiang",
  anim_type = "offensive",
  events = {fk.EventPhaseStart, fk.TargetSpecified, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self.name) then
      if event == fk.EventPhaseStart then
        return player.phase == Player.Play
      elseif event == fk.TargetSpecified then
        return data.card.trueName == "slash" and data.card.skillName == self.name
      else
        return data.card and data.card:getMark("shenqiang_buff") > 0
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      local card = player.room:askForCard(player, 2, 2, false, self.name, true, ".|.|.|hand", "#ev__shenqiang-card")
      if #card > 0 then
        self.cost_data = card
        return true
      end
    elseif event == fk.TargetSpecified then
      return player.room:askForSkillInvoke(player, self.name)
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      room:setPlayerMark(player, "BypassTimesLimit", 1)
      U.askForUseVirtualCard(room, player, "ev__slash", self.cost_data, self.name, "#ev__shenqiang", true, true, true)
      room:setPlayerMark(player, "BypassTimesLimit", 0)
    elseif event == fk.TargetSpecified then
      local judge = {
        who = player,
        reason = self.name,
        pattern = ".|.|heart,diamond",
      }
      room:judge(judge)
      if judge.card.color == Card.Red then
        data.disresponsive = true
      end
      if judge.card.suit == Card.Heart then
        room:setCardMark(data.card, "shenqiang_buff", 1)
      end
    elseif event == fk.Damage then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    end
  end,

  refresh_events = {fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name) and data.card:getMark("shenqiang_buff") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setCardMark(data.card, "shenqiang_buff", 0)
  end,
}

local ev__yunming = fk.CreateTriggerSkill{
  name = "ev__yunming",
  anim_type = "control",
  events = {fk.AskForRetrial},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:distanceTo(target) <= 1 and player:usedSkillTimes(self.name, Player.HistoryRound) < player.hp
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(2)
    local ids, choice = U.askforChooseCardsAndChoice(player, cards, {"OK"}, self.name, "#ev__yunming")
    table.removeOne(cards, ids[1])
    room:retrial(Fk:getCardById(ids[1]), player, data, self.name)
    room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true, target.id)
  end,
}

Remilia:addSkill(ev__shenqiang)
Remilia:addSkill(ev__yunming)

Fk:loadTranslationTable{
  ["com__remilia"] = "蕾米莉亚",
  ["designer:com__remilia"] = "夜之礼赞",
  ["ev__shenqiang"] = "神枪",
  [":ev__shenqiang"] = "阶段技（始），你可将两张手牌当无距离限制的【杀】使用；当此【杀】指定一个目标后，你可判定，若结果为：红色，则此【杀】不是【闪】的合法目标；红桃，则当此【杀】造成伤害后，你回复1点体力。",
  ["#ev__shenqiang-card"] = "神枪：你可以选择两张手牌，然后将这些牌当【杀】使用",
  ["#ev__shenqiang"] = "神枪：请选择【杀】的目标",
  ["ev__yunming"] = "运命",
  [":ev__yunming"] = "轮次技（X），当你距离1以内的角色的判定牌生效前，你可观看牌堆顶的两张牌，用其中的一张牌代替之，然后获得另一张牌（X为你的体力值）。",
  ["#ev__yunming"] = "请选择其中一张牌代替判定牌，然后你获得另一张牌",
}

local Momizi = General(extension, "com__momizi", "com", 4, 4, General.Female)
local ev__qianlizhishi = fk.CreateActiveSkill{
  name = "ev__qianlizhishi",
  prompt = "#qianlizhishi-prompt",
  target_num = 1,
  card_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) <= player:getMark("qianlizhishi-turn")
  end,
  target_filter = function (self, to_select, selected, _, _, _, player)
    return #selected == 0 and to_select ~= player.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local choice = U.askforViewCardsAndChoice(player, target:getCardIds(Player.Hand), {"qianlizhishi1","qianlizhishi2","qianlizhishi3"}, self.name)
    local to_throw = table.filter(target:getCardIds(Player.Hand), function(id) return Fk:getCardById(id).type == Card.TypeTrick end)
    if choice == "qianlizhishi1" then
      to_throw = table.filter(target:getCardIds(Player.Hand), function(id) return Fk:getCardById(id).trueName == "slash" end)
    end
    if choice == "qianlizhishi3" then
      room:setPlayerMark(player, "qianlizhishi-turn", 1)
    else
      room:moveCardTo(to_throw, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, effect.from)
    end
  end,
}

Momizi:addSkill(ev__qianlizhishi)

Fk:loadTranslationTable{
  ["com__momizi"] = "犬走椛",
  ["designer:com__momizi"] = "KINGDOM43",
  ["ev__qianlizhishi"] = "千里之视",
  [":ev__qianlizhishi"] = "出牌阶段限一次，你可观看一名角色的手牌，然后选择一项：1.弃置其中的所有【杀】或所有魔法牌；2.于本回合内将“限一次”改为“限两次”。",
  ["#qianlizhishi-prompt"] = "你可观看一名角色的手牌",
  ["qianlizhishi1"] = "弃置所有【杀】",
  ["qianlizhishi2"] = "弃置所有魔法牌",
  ["qianlizhishi3"] = "此技能限两次",
}

local Inaba = General(extension, "com__inaba", "com", 3, 3, General.Female)

local ev__kaiyun = fk.CreateActiveSkill{
  name = "ev__kaiyun",
  prompt = "你可以将一张牌置于牌堆顶",
  card_num = 1,
  target_num = 0,
  card_filter = Util.TrueFunc,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    room:moveCardTo(effect.cards[1], Card.DrawPile, nil, fk.ReasonPut, self.name)
    room:addPlayerMark(room:getPlayerById(effect.from), "kaiyun_buff")
  end
}

local kaiyun_trigger = fk.CreateTriggerSkill{
  name = "#kaiyun_trigger",
  anim_type = "support",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and target:inMyAttackRange(player) and player:getMark("kaiyun_buff") > 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#ev__kaiyun::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, self.name)
    local card = room:askForCard(player, 1, 1, true, self.name, false, ".", "#kaiyun-give::"..target.id)
    room:obtainCard(target.id, card[1], false, fk.ReasonGive)
  end,
  refresh_events = {fk.TurnStart}, 
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player:getMark("kaiyun_buff") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "kaiyun_buff", 0)
  end
}

ev__kaiyun:addRelatedSkill(kaiyun_trigger)
Inaba:addSkill(ev__kaiyun)

local ev__gouxian = fk.CreateTriggerSkill{
  name = "ev__gouxian",
  --mute = true,
  anim_type = "control",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.from == player.id and move.to and move.to ~= player.id and move.toArea == Card.PlayerHand then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        local cards = {}
        if move.from == player.id and move.to and move.to ~= player.id and move.toArea == Card.PlayerHand then
          local to = room:getPlayerById(move.to)
          for _, info in ipairs(move.moveInfo) do
            if table.contains(to:getCardIds("h"), info.cardId) then
              table.insertIfNeed(cards, info.cardId)
            end
          end
          if #cards > 0 then
            local ids = table.simpleClone(cards)
            if #cards > 1 then
              ids, _ = U.askforChooseCardsAndChoice(player, cards, {"OK"}, self.name, "#ev__gouxian")
            end
            to:showCards(ids)
            local mark = to:getTableMark("gouxian-turn")
            table.insertIfNeed(mark, Fk:getCardById(ids[1]):getSuitString())
            room:setPlayerMark(to, "gouxian-turn", mark)
            --room:setPlayerMark(to, "gouxian-turn", Fk:getCardById(ids[1]):getSuitString())
          end
        end
      end
    end
  end,
}

local gouxian_prohibit = fk.CreateProhibitSkill{
  name = "#ev__gouxian_prohibit",
  prohibit_use = function(self, player, card)
    if card and player:getMark("gouxian-turn") ~= 0 then
      --return card:getSuitString() == player:getMark("gouxian-turn")
      return table.contains(player:getTableMark("gouxian-turn"), card:getSuitString())
    end
  end,
}

ev__gouxian:addRelatedSkill(gouxian_prohibit)
Inaba:addSkill(ev__gouxian)
Fk:loadTranslationTable{
  --["com__inaba"] = "因幡天为",
  ["com__inaba"] = "因幡帝",
  ["designer:com__inaba"] = "辰木",
  ["ev__kaiyun"] = "开运",
  [":ev__kaiyun"] = "阶段技，你可将一张牌置于牌堆顶；若如此做，直至你的下回合开始，其他角色的回合开始时，若你在其攻击范围内，则你可摸一张牌并将一张牌交给其。",
  ["#kaiyun_trigger"] = "开运",
  ["#ev__kaiyun"] = "你可摸一张牌并将一张牌交给%dest",
  ["#kaiyun-give"] = "开运：请选择交给%dest的牌",
  ["ev__gouxian"] = "构陷",
  [":ev__gouxian"] = "其他角色获得你的牌后，你可展示其中的一张牌，然后你可令其于当前回合内不能使用与此牌花色相同的牌。",
  ["#ev__gouxian"] = "请展示其中一张牌",
}

local Mystia = General(extension, "com__mystia", "com", 3, 3, General.Female)

local ev__yemang = fk.CreateTriggerSkill{
  name = "ev__yemang",
  anim_type = "control",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryRound) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(table.filter(room.alive_players, function (p)
    return #table.filter(p:getCardIds("h"), function(id)
    return Fk:getCardById(id):getMark("@@shown-inhand") > 0 end) > 0 end), Util.IdMapper), 1, 1, "#ev__yemang-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local shown = to:getTableMark("@$shown")
    local n = #shown + 1
    if #shown > 0 then
      EV.ConcealCards(room, to, shown, self.name, player)
    end
    room:setPlayerMark(to, "@ev__yemang-turn", n)
  end,
  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and target.id == data.from and target:getMark("@ev__yemang-turn") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:removePlayerMark(target, "@ev__yemang-turn", 1)
  end
}

local yemang_prohibit = fk.CreateProhibitSkill{
  name = "#ev__yemang_prohibit",
  is_prohibited = function(self, from, to, card)
    return from:getMark("@ev__yemang-turn") > 0 and from ~= to
  end,
}

local ev__gaoyin = fk.CreateTriggerSkill{
  name = "ev__gaoyin",
  events = {fk.TargetSpecified, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase ~= Player.NotActive then
      if event == fk.TargetSpecified then
        local hcands = player.room:getPlayerById(data.to):getCardIds(Player.Hand)
        local unshown = table.filter(hcands, function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
        return #unshown > 0
      else
        return player.phase == Player.Finish
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      return room:askForSkillInvoke(player, self.name, nil, "#ev__gaoyin::"..data.to)
    else
      local to = room:askForChoosePlayers(player, table.map(table.filter(room.alive_players, function (p) return #p:getTableMark("@$shown") > 0 end),
      Util.IdMapper), 1, 1, "#ev__gaoyin-choose", self.name, true)
      if #to > 0 then
        self.cost_data = to[1]
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      local to = room:getPlayerById(data.to)
      --local card = room:askForCardChosen(player, to, "h", self.name)
      local unshown = table.filter(to:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@shown-inhand") == 0 end)
      local card = table.random(unshown, 1)
      EV.OpenCards(room, to, card, self.name, player)
      room:setCardMark(Fk:getCardById(card[1]), "gaoyin-turn", 1)
    else
      local to = room:getPlayerById(self.cost_data)
      local shown = to:getTableMark("@$shown")
      room:askForDiscard(to, 1, 1, true, self.name, false, tostring(Exppattern{ id = shown }), "#ev__gaoyin-discard")
    end
  end,
}

local gaoyin_effect = fk.CreateProhibitSkill{
  name = "#ev__gaoyin_effect",
  prohibit_use = function(self, player, card)
    return card and card:getMark("gaoyin-turn") > 0
  end,
}

ev__yemang:addRelatedSkill(yemang_prohibit)
ev__gaoyin:addRelatedSkill(gaoyin_effect)
Mystia:addSkill(ev__yemang)
Mystia:addSkill(ev__gaoyin)

Fk:loadTranslationTable{
  ["com__mystia"] = "米斯蒂娅",
  ["designer:com__mystia"] = "KINGDOM43",
  ["ev__yemang"] = "夜盲之曲",
  [":ev__yemang"] = "轮次技，一名角色的回合开始时，你可暗置一名角色的所有手牌，令除其之外的角色于此回合内不是其使用牌的合法目标，直至其于此回合内使用第X张牌时（X为你以此法暗置其手牌的数量+1）。",
  ["#ev__yemang-choose"] = "夜盲之曲：你可暗置一名角色的所有手牌",
  ["@ev__yemang-turn"] = "夜盲",
  ["ev__gaoyin"] = "放歌高吟",
  [":ev__gaoyin"] = "当你于回合内使用牌指定一个目标后，你可明置其一张手牌，令其于当前回合内不能使用此牌。结束阶段，你可令一名角色弃置一张明置手牌。",
  ["#ev__gaoyin"] = "你可明置%dest一张手牌", 
  ["#ev__gaoyin-choose"] = "你可令一名角色弃置一张明置手牌", 
  ["#ev__gaoyin-discard"] = "请弃置一张明置手牌",
  ["#ev__gaoyin_effect"] = "高吟",
}

local Oren = General(extension, "com__oren", "com", 4)
local Duri_Noko = fk.CreateActiveSkill{
  name = "Duri_Noko",
  anim_type = "control",
  prompt = "你可弃置你攻击范围内的任意名角色的各一张牌",
  min_target_num = 1,
  max_target_num = 99,
  card_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, _, _, _, player)
    return to_select ~= player.id and player:inMyAttackRange(Fk:currentRoom():getPlayerById(to_select))
    and not Fk:currentRoom():getPlayerById(to_select):isNude()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local n = 0
    for _, p in ipairs(effect.tos) do
      local target = room:getPlayerById(p)
      if not target.dead and not target:isNude() then
        local cid = room:askForCardChosen(player, target, "he", self.name)
        if cid then
          room:moveCardTo(cid, Card.DiscardPile, nil, fk.ReasonDiscard, self.name, "", true, player.id)
          n = n + 1
        end
      end
    end
    if n > player:getLostHp() + 1 then
      room:loseHp(player, 1, self.name)
    end
  end,
}
Oren:addSkill(Duri_Noko)
Fk:loadTranslationTable{
  ["com__oren"] = "凰莲严之介",
  ["designer:com__oren"] = "神域",
  ["Duri_Noko"] = "DuriNoko",
  [":Duri_Noko"] = "出牌阶段限一次，你可弃置攻击范围内的任意名角色各一张牌，若你以此法弃置的牌多于X张，则你失去1点体力（X为你已损失的体力值+1）。",
}

local shangshanqianxin = General(extension, "com__shangshanqianxin", "com", 4, 4, General.Female)

local ev__chexuan = fk.CreateTriggerSkill{
  name = "ev__chexuan",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card.trueName == "slash" then
      return player:usedSkillTimes(self.name) < player:getLostHp() + 1
    end
  end,
  on_use = function(self, event, target, player, data)
    local n = 1 
    if player:isWounded() then n = 2 end
    local choices = player.room:askForChoices(player, {"ev__chexuan1", "ev__chexuan2"}, 1, n, self.name)
    if table.contains(choices, "ev__chexuan1") then
      player:drawCards(1, self.name)
    end
    if table.contains(choices, "ev__chexuan2") then
      player:addCardUseHistory("slash", -1)
    end
  end,
}

shangshanqianxin:addSkill(ev__chexuan)

Fk:loadTranslationTable{
  ["com__shangshanqianxin"] = "上杉谦信",
  ["designer:com__shangshanqianxin"] = "亚里亚",
  ["ev__chexuan"] = "车悬之剑",
  ["ev__chexuan1"] = "摸一张牌",
  ["ev__chexuan2"] = "不计入次数限制",
  [":ev__chexuan"] = "回合技（X），当你使用【杀】时，你可选择一项：1.摸一张牌；2.令此【杀】不计入次数限制。若你已受伤，则改为选择两项（X为你已损失的体力值+1）。",
}

local Shino = General(extension, "com__shino", "com", 3, 3, General.Female)

local bingzhixinjing = fk.CreateTriggerSkill{
  name = "bingzhixinjing",
  refresh_events = {fk.CardEffectCancelledOut, fk.TurnStart},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self.name) and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardEffectCancelledOut then
      room:addPlayerMark(player, "@@bingzhixinjing")
    else
      room:setPlayerMark(player, "@@bingzhixinjing", 0)
    end
  end,
}

local bingzhixinjing_range = fk.CreateAttackRangeSkill{
  name = "#bingzhixinjing_range",
  correct_func = function (self, from, to)
    if from:hasSkill(self) and from:getMark("@@bingzhixinjing") == 0 then
      return #from:getCardIds(Player.Hand)
    end
  end,
}

local bingzhixinjing_distance = fk.CreateDistanceSkill{
  name = "#bingzhixinjing_distance",
  frequency = Skill.Compulsory,
  correct_func = function(self, from, to)
    if to:hasSkill(self) and to:getMark("@@bingzhixinjing") == 0  then
      return #to:getCardIds(Player.Hand)
    end
  end,
}

local bingzhixinjing_maxcards = fk.CreateMaxCardsSkill{
  name = "#bingzhixinjing_maxcards",
  exclude_from = function(self, player, card)
    return player:hasSkill(self) and player:getMark("@@bingzhixinjing") == 0 and card.trueName == "slash"
  end,
}

local youlingzidan = fk.CreateTriggerSkill{
  name = "youlingzidan",
  anim_type = "offensive",
  events ={fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryRound) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local success, dat = room:askForUseViewAsSkill(player, "youlingzidan_viewas", "#youlingzidan-slash", true, {bypass_times = true})
    if success then
      local card = Fk.skills["youlingzidan_viewas"]:viewAs(dat.cards)
      if player.dead then return end
        local use = {
        from = player.id,
        tos = table.map(dat.targets, function(p) return {p} end),
        card = card,
        extraUse = true,
        additionalDamage = 1,
      }
      room:useCard(use)
      if not use.damageDealt then
        room:addPlayerMark(target, "@@youlingzidan-turn")
      end
    end
  end,
}

local youlingzidan_viewas = fk.CreateViewAsSkill{
  name = "youlingzidan_viewas",
  pattern = "slash",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("ev__slash")
    card:addSubcard(cards[1])
    card.skillName = "youlingzidan"
    return card
  end,
}

local youlingzidan_tar = fk.CreateTargetModSkill{
  name = "#youlingzidan_targetmod",
  residue_func = function(self, player, skill, scope, card)
    if player:getMark("@@youlingzidan-turn") > 0 and skill.trueName == "slash_skill" and card.trueName == "slash" then
      return 1
    end
  end,
}

Fk:addSkill(youlingzidan_viewas)
bingzhixinjing:addRelatedSkill(bingzhixinjing_range)
bingzhixinjing:addRelatedSkill(bingzhixinjing_distance)
bingzhixinjing:addRelatedSkill(bingzhixinjing_maxcards)
youlingzidan:addRelatedSkill(youlingzidan_tar)
Shino:addSkill(bingzhixinjing)
Shino:addSkill(youlingzidan)

Fk:loadTranslationTable{
  ["com__shino"] = "朝田诗乃",
  ["designer:com__shino"] = "小妖辰末+夜之礼赞",
  ["bingzhixinjing"] = "冰之心境",
  ["@@bingzhixinjing"] = "冰之心境失效",
  [":bingzhixinjing"] = "锁定技，你的攻击范围与其他角色与你的距离均+X，你的【杀】不计入手牌上限（X为你的手牌数）。当你使用的牌被抵消时，此技能失效直至你的下回合开始。",
  ["youlingzidan"] = "幽灵子弹",
  ["youlingzidan_viewas"] = "幽灵子弹",
  [":youlingzidan"] = "轮次技，一名角色的回合开始时，你可将一张黑色牌当【杀】使用，此【杀】造成的伤害+1；若此【杀】未造成伤害，则其使用【杀】的次数上限于此回合内+1。",
  ["#youlingzidan-slash"] = "幽灵子弹：你可以将一张黑色牌当【杀】使用",
  ["@@youlingzidan-turn"] = "幽灵子弹",
}

local Taiga = General(extension, "com__taiga", "com", 3, 3, General.Female)

local ev__yexi = fk.CreateActiveSkill{
  name = "ev__yexi",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isNude()
  end,
  card_filter = Util.FalseFunc,
  target_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 6)))
    local player = room:getPlayerById(effect.from)
    local target = room:getOtherPlayers(player)[math.random(1, #room:getOtherPlayers(player))]
    room:sendLog{
      type = "#ev__yexi",
      from = player.id,
      to = {target.id},
      toast = true,
    }
    local card = room:askForCard(player, 1, 1, true, self.name, false, ".", "#ev__yexi-give:"..target.id)
    room:moveCardTo(card, Player.Hand, target, fk.ReasonGive, self.name, nil, false, player.id)
    if player:isAlive() and target:isAlive() and room:askForSkillInvoke(player, self.name, nil, "ev__yexi-invoke") then
      local all_choices = {"ev__yexi1:"..player.id.."::"..Fk:getCardById(card[1]):toLogString(), "ev__yexi2:"..player.id.."::"..Fk:getCardById(card[1]):toLogString()}
      local choice = room:askForChoice(target, all_choices, self.name)
      if choice == all_choices[1] then
        room:damage({
          from = player,
          to = target,
          damage = 1,
          damageType = fk.NormalDamage,
          skillName = self.name,
        })
        if player:isAlive() and target:isAlive() then
          room:moveCardTo(card, Player.Hand, player, fk.ReasonGive, self.name, nil, true)
        end
      else
        local ids = table.filter(target:getCardIds("h"), function (id) return Fk:getCardById(id).type == Fk:getCardById(card[1]).type end)
        if #ids > 0 then
          local cards, _ = U.askforChooseCardsAndChoice(player, ids, {"OK"}, self.name, "#ev__yexi-choose", {"Cancel"}, 1, 999, target:getCardIds("h"))
          if #cards > 0 then
            room:moveCardTo(cards, Player.Hand, player, fk.ReasonPrey, self.name, nil, false, player.id)
          end
        end
      end
    end
  end,
}

local ev__jiaoman = fk.CreateTriggerSkill{
  name = "ev__jiaoman",
  anim_type = "offensive",
  events = {fk.AfterCardUseDeclared, fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.DamageInflicted then
      local cards = table.filter(player:getCardIds("he"), function (id) return Fk:getCardById(id).number < data.card.number end)
      local ids = player.room:askForDiscard(player, 1, 1, true, self.name, true, tostring(Exppattern{ id = cards }), "#jiaoman-discard:::"..data.card.number)
      return #ids > 0
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.DamageInflicted then
      return true
    else
      player.room:setPlayerMark(player, "ev__jiaoman-turn", data.card.number)
    end
  end,

  refresh_events = {fk.HandleAskForPlayCard, fk.CardUseFinished},
  can_refresh = function(self, event, target, player, data)
    if event == fk.HandleAskForPlayCard then
      return data.eventData and data.eventData.from == player.id and player:getMark("ev__jiaoman-turn") ~= 0
    else
      return target == player and player:hasSkill(self) and player:getMark("ev__jiaoman-turn") ~= 0
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.HandleAskForPlayCard then
      if not data.afterRequest then
        room:setBanner("ev__jiaoman_user", player.id)
      else
        room:setBanner("ev__jiaoman_user", 0)
      end
    else
      room:setPlayerMark(player, "ev__jiaoman-turn", 0)
    end
  end,
}

local jiaoman_prohibit = fk.CreateProhibitSkill{
  name = "#ev__jiaoman_prohibit",
  prohibit_use = function(self, player, card)
    local room = Fk:currentRoom()
    local user = room:getBanner("ev__jiaoman_user")
    if user and player.id ~= user then
      user = room:getPlayerById(user)
      local number = user:getMark("ev__jiaoman-turn")
      if number == 0 then return end
      local subcards = card:isVirtual() and card.subcards or {card.id}
      return #subcards == 0 or card.number < number or table.find(subcards, function(id) return room:getCardArea(id) ~= Card.PlayerHand end)
    end
  end,
}

ev__jiaoman:addRelatedSkill(jiaoman_prohibit)
Taiga:addSkill(ev__yexi)
Taiga:addSkill(ev__jiaoman)

Fk:loadTranslationTable{
  ["com__taiga"] = "逢坂大河",
  ["designer:com__taiga"] = "陆丿伯言",
  ["ev__yexi"] = "夜袭",
  [":ev__yexi"] = "阶段技，你可随机选择一名角色并将一张牌交给其，然后你可令其选择一项：1.受到你造成的1点伤害，然后将此牌交给你；2.令你观看其手牌并获得其中任意张与此牌类别相同的牌。",
  ["#ev__yexi"] = "%from 随机选择了 %to",
  ["#ev__yexi-give"] = "请将一张牌交给%src",
  ["ev__yexi-invoke"] = "你可以令对方选择一项",
  ["ev__yexi1"] = "受到%src造成的1点伤害，然后将%arg交给%src",
  ["ev__yexi2"] = "令%src观看你的手牌，获得与%arg类别相同的牌",
  ["#ev__yexi-choose"] = "夜袭：请选择类别相同的牌",
  ["ev__jiaoman"] = "娇蛮",
  ["#ev__jiaoman_prohibit"] = "娇蛮",
  [":ev__jiaoman"] = "你使用的牌不是点数小于此牌的牌的合法目标。当你受到牌造成的伤害时，可弃置一张点数小于此牌的牌，防止此伤害。",
  ["#jiaoman-discard"] = "你可弃置一张点数小于%arg的牌，防止此伤害",
}

local aria = General(extension, "com__aria", "com", 4, 4, General.Female)

local ev__shuangzhan_buff = fk.CreateTriggerSkill{
  name = "#ev__shuangzhan_buff",
  mute = true,
  events = { fk.TargetSpecified },
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and
      data.card and data.card.trueName == "slash" and data.card.skillName == "ev__shuangzhan"
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
    if use_event == nil then return end
    room:addPlayerMark(to, fk.MarkArmorNullified)
    use_event:addCleaner(function()
      room:removePlayerMark(to, fk.MarkArmorNullified)
    end)
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash"
  end,
  on_refresh = function(self, event, target, player, data)
    local mark = player:getTableMark("ev__shuangzhan-turn")
    table.insertIfNeed(mark, data.card.color)
    player.room:setPlayerMark(player, "ev__shuangzhan-turn", mark)
  end,
}

local ev__shuangzhan_tar = fk.CreateTargetModSkill{
  name = "#ev__shuangzhan_targetmod",
  residue_func = function(self, player, skill, scope, card)
    if card and card.color == Card.Red then return 0 end
    if player:hasSkill(self.name) and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then--and card and card.trueName == "slash" 
      return 999
    end
  end,
  distance_limit_func =  function(self, player, skill, card)
    if player:hasSkill(self.name) and card and card.trueName == "slash" and card.color == Card.Red then
      return 999
    end
  end,
}

local ev__shuangzhan = fk.CreateViewAsSkill{
  name = "ev__shuangzhan",
  anim_type = "offensive",
  pattern = "slash",
  card_filter = function(self, to_select, selected)
    if #selected == 1 then return false end
    local colors = Self:getTableMark("ev__shuangzhan-turn")
    return not table.contains(colors, Fk:getCardById(to_select).color)
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then
      return nil
    end
    local c = Fk:cloneCard("ev__slash")
    c.skillName = self.name
    c:addSubcard(cards[1])
    return c
  end,
}

ev__shuangzhan:addRelatedSkill(ev__shuangzhan_buff)
ev__shuangzhan:addRelatedSkill(ev__shuangzhan_tar)
aria:addSkill(ev__shuangzhan)

Fk:loadTranslationTable{
  ["com__aria"] = "亚里亚",
  ["designer:com__aria"] = "亚里亚",
  ["ev__shuangzhan"] = "绯天双战",
  [":ev__shuangzhan"] = "你可将一张牌（不得与你于此回合内使用过的【杀】颜色相同）当无视防具的【杀】使用或打出。你使用黑色【杀】无次数限制，红色【杀】无距离限制。",
}

local Ysera = General(extension, "com__ysera", "com", 4, 4, General.Female)

local ev__huanyan = fk.CreateTriggerSkill{
  name = "ev__huanyan",
  events = {fk.EventPhaseStart, fk.RoundStart},
  derived_piles = {"$ev__huanyan"},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Finish
    else
      return player:hasSkill(self) and #player:getPile("$ev__huanyan") > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return player.room:askForSkillInvoke(player, self.name)
    else
      local card = player.room:askForCard(player, 1, 1, false, self.name, true, ".|.|.|$ev__huanyan|.|.", "#ev__huanyan-invoke", "$ev__huanyan")
      if #card > 0 then
        self.cost_data = card[1]
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      room:moveCardTo(room:getNCards(2), Card.PlayerSpecial, player, fk.ReasonJustMove, self.name, "$ev__huanyan", false)
    else
      local suit = Fk:getCardById(self.cost_data).suit
      room:moveCardTo(self.cost_data, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "", "", true)
      if suit == Card.Spade then
        for _, p in ipairs(room:getOtherPlayers(player)) do
          room:damage({
            from = player,
            to = p,
            damage = 1,
            damageType = fk.NormalDamage,
            skillName = self.name,
          })
        end
      else
        local prompt = "#huanyan-"..U.ConvertSuit(suit,"int","str")
        local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, prompt, self.name, false)
        to = room:getPlayerById(to[1])
        if suit == Card.Heart then
          to:drawCards(1, self.name)
          room:setPlayerMark(to, "@huanyan-round", {U.ConvertSuit(suit,"int","sym")})
        elseif suit == Card.Diamond then
          if #to:getCardIds("ej") > 0 then
            room:moveCardTo(to:getCardIds("ej"), Player.Hand, to, fk.ReasonJustMove, self.name, nil, false, to.id)
          end
        elseif suit == Card.Club then
          room:loseHp(to, 1, self.name)
          if not to.dead then
            room:setPlayerMark(to, "@huanyan-round", {U.ConvertSuit(suit,"int","sym")})
          end
        end
      end
    end
  end,

  refresh_events = {fk.CardUsing},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self.name, true, true) and table.contains(target:getTableMark("@huanyan-round"), "log_club")
    and data.card.trueName == "slash"
  end,
  on_refresh = function(self, event, target, player, data)
    data.additionalDamage = (data.additionalDamage or 0) + 1
  end,
}

local huanyan_prohibit = fk.CreateProhibitSkill{
  name = "#ev__huanyan_prohibit",
  is_prohibited = function(self, from, to, card)
    return table.contains(to:getTableMark("@huanyan-round"), "log_heart") and card.type == Card.TypeTrick
  end,
}

ev__huanyan:addRelatedSkill(huanyan_prohibit)
Ysera:addSkill(ev__huanyan)

Fk:loadTranslationTable{
  ["com__ysera"] = "伊瑟拉",
  ["designer:com__ysera"] = "七哀",
  ["ev__huanyan"] = "幻魇",
  ["$ev__huanyan"] = "幻魇",
  ["@huanyan-round"] = "幻魇",
  ["#ev__huanyan_prohibit"] = "幻魇",
  ["#ev__huanyan-invoke"] = "你可将一张“幻魇”牌置入弃牌堆",
  [":ev__huanyan"] = "结束阶段，你可将牌堆顶的两张牌扣置于角色牌上。每轮开始时，你可弃一张“幻魇”牌，若此牌花色为："..
  "<br />黑桃：你对所有其他角色各造成1点伤害；"..
  "<br />梅花：你令一名角色失去1点体力，其于本轮内使用【杀】造成的伤害+1；"..
  "<br />方块：你令一名角色获得其场上的所有牌；"..
  "<br />红桃：你令一名角色摸一张牌，其于本轮内不是魔法牌的合法目标。",
  ["#huanyan-heart"] = "幻魇：你令一名角色摸一张牌，其于本轮内不是魔法牌的合法目标",
  ["#huanyan-diamond"] = "幻魇：你令一名角色获得其场上的所有牌",
  ["#huanyan-club"] = "幻魇：你令一名角色失去1点体力，其于本轮内使用【杀】造成的伤害+1",
}

local heartqueen = General(extension, "com__heartqueen", "com", 3, 3, General.Female)

local ev__xuanxing = fk.CreateActiveSkill{
  name = "ev__xuanxing",
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  prompt = "你可将一张【杀】交给一名其他角色",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).trueName == "slash"
  end,
  target_filter = function (self, to_select, selected, _, _, _, player)
    return #selected == 0 and to_select ~= player.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:obtainCard(target.id, Fk:getCardById(effect.cards[1]), false, fk.ReasonGive, player.id)
    if player.dead or target.dead then return end
    local all_choices = {"ev__xuanxing1", "ev__xuanxing2"}
    local choice = room:askForChoice(target, all_choices, self.name)
    if choice == all_choices[1] then
      player:drawCards(1, self.name)
      local targets = table.map(table.filter(room:getOtherPlayers(target), function(p)
      return player ~= p and target:canUseTo(Fk:cloneCard("ev__slash"), p, {bypass_distances = true, bypass_times = true}) end), Util.IdMapper)
      if #targets == 0 then return end
      local tos = room:askForChoosePlayers(player, targets, 1, 1, "#ev__xuanxing-choose::"..target.id, self.name, false, true)
      local to
      if #tos > 0 then
        to = tos[1]
      else
        to = table.random(targets)
      end
      room:doIndicate(target.id, {to})
      local ids = room:askForCard(target, 1, 1, true, self.name, false, "slash", "#xuanxing-slash")
      if #ids == 0 then
        local slashs = table.filter(target:getCardIds("h"), function (id) return Fk:getCardById(id).trueName == "slash" end)
        if #slashs > 0 then
          ids = {table.random(slashs, 1)}
        end
      end
      if #ids > 0 then
        local use = {
          from = target.id,
          tos = {{to}},
          card = Fk:getCardById(ids[1]),
          extraUse = true,
        }
        room:useCard(use)
      end
    else
      room:damage({
        from = player,
        to = target,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end,
}

local ev__baozhen = fk.CreateTriggerSkill{
  name = "ev__baozhen",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target ~= player and target:getMark("ev__baozhen-turn") == 0--偷懒没用计数器
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(target, "ev__baozhen-turn")
    if player:isWounded() then
      room:recover({
        who = player,
        num = 1,
        recoverBy = player,
        skillName = self.name
      })
    else
      player:drawCards(1, self.name)
    end
  end,
}

heartqueen:addSkill(ev__xuanxing)
heartqueen:addSkill(ev__baozhen)

Fk:loadTranslationTable{
  ["com__heartqueen"] = "红心女皇",
  ["designer:com__heartqueen"] = "木因",
  ["ev__xuanxing"] = "宣刑",
  [":ev__xuanxing"] = "你可将一张【杀】交给一名其他角色，令其选择一项：1.你摸一张牌并选择另一名其他角色，其对此角色使用【杀】（无距离限制）；2.受到你造成的1点伤害。",
  ["ev__xuanxing1"] = "使用【杀】",
  ["ev__xuanxing2"] = "受到1点伤害",
  ["#ev__xuanxing-choose"] = "请选择%dest使用【杀】的目标",
  ["#xuanxing-slash"] = "请选择使用的【杀】",
  ["ev__baozhen"] = "暴鸩",
  [":ev__baozhen"] = "锁定技，其他角色于当前回合内首次进入濒死状态时，若你：已受伤，则你回复1点体力；未受伤，则你摸一张牌。",
}

local Ran = General(extension, "com__ran", "com", 3, 3, General.Female)

local ev__tianhu = fk.CreateTriggerSkill{
  name = "ev__tianhu",
  anim_type = "support",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and not player:isKongcheng() and
    (data.card.trueName == "slash" or data.card:isCommonTrick()) and #player.room.alive_players > 2
  end,
  on_use = function(self, event, target, player, data)
    local targets = player.room:getOtherPlayers(player)
    table.removeOne(targets, player.room:getPlayerById(data.from))
    local n = player:getHandcardNum()
    U.askForDistribution(player, player:getCardIds("h"), targets, self.name, n, n)
    --table.insertIfNeed(data.nullifiedTargets, player.id)
    EV.nullifiedCard(data, data.card, player)
    player.room:addPlayerMark(player, "ev__tianhu-turn")
  end,
}

local tianhu_prohibit = fk.CreateProhibitSkill{
  name = "#ev__tianhu_prohibit",
  is_prohibited = function(self, from, to, card)
    return to:getMark("ev__tianhu-turn") > 0
  end,
}

ev__tianhu:addRelatedSkill(tianhu_prohibit)
Ran:addSkill(ev__tianhu)

local ev__twelve = fk.CreateTriggerSkill{
  name = "ev__twelve",
  anim_type = "control",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local room = player.room
      local ids = {}
      local logic = room.logic
      local events = logic.event_recorder[GameEvent.MoveCards] or Util.DummyTable
      if not logic:getCurrentEvent():findParent(GameEvent.Turn, true) then return {} end
      local end_id = logic:getCurrentEvent():findParent(GameEvent.Turn, true).id
      for i = #events, 1, -1 do
        local e = events[i]
        if e.id < end_id then break end
        for _, move in ipairs(e.data) do
          if move.toArea == Card.DiscardPile then
            for _, info in ipairs(move.moveInfo) do
              if Fk:getCardById(info.cardId).sub_type == Card.SubtypeWeapon then
                table.insertIfNeed(ids, info.cardId)
              end
            end
          end
        end
      end
      local cards = table.simpleClone(ids)
      for _, id in ipairs(cards) do
        if room:getCardArea(id) ~= Card.DiscardPile then
          table.removeOne(ids, id)
        end
      end
      if #ids > 0 then
        self.cost_data = ids
        return true
      end
    end
  end,
  on_cost = function(_, _, _, player, _)
    return player.room:askForSkillInvoke(player, "twelves_party")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local get = U.askforChooseCardsAndChoice(player, self.cost_data, {"OK"}, self.name, "请选择一张武器牌获得之")
    if #get > 0 then
      room:moveCardTo(get, Card.PlayerHand, player, fk.ReasonJustMove, self.name, "", true)
      U.askForUseVirtualCard(room, player, "ev__slash", get, self.name, "#twelves_party")
    end
  end,
}
Ran:addSkill(ev__twelve)
Fk:loadTranslationTable{
  ["com__ran"] = "八云蓝",
  ["designer:com__yukari"] = "小鸟游星羽",
  ["ev__tianhu"] = "天狐公主",
  [":ev__tianhu"] = "当你成为【杀】或即时魔法牌的目标时，你可将所有手牌交给除此牌的使用者外的至少一名其他角色；然后你取消你自己，且你于当前回合内不是牌的合法目标。",
  ["#ev__tianhu_prohibit"] = "天狐",
  ["ev__twelve"] = "十二之宴",
  [":ev__twelve"] = "一名角色的回合结束时，你可获得弃牌堆里于此回合内置入弃牌堆的一张武器牌，然后你可将此牌当【杀】使用。",
  ["twelves_party"] = "十二神将之宴",
  ["#twelves_party"] = "你可将此牌当【杀】使用",
}

local Yukari = General(extension, "com__yukari", "com", 3, 3, General.Female)

local ev__shenyin = fk.CreateTriggerSkill{
  name = "ev__shenyin",
  anim_type = "control",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    local n = player:usedSkillTimes(self.name, Player.HistoryRound)
    if n == 0 then
      return player.room:askForSkillInvoke(player, self.name)
    else
      local cards = player.room:askForDiscard(player, n, n, true, self.name, true, ".", "#ev__shenyin-throw:::"..n)
      return #cards > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local id = EV.chooseCardonBoard(room, player, self.name, "#ev__shenyin-choose")
    if id then
      room:moveCards({
        ids = {id},
        from = room:getCardOwner(id).id,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonPut,
        skillName = self.name,
        drawPilePosition = -1,
      })
    else
      local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#ev__shenyin-draw", self.name, false)
      if #tos > 0 then
        local to = room:getPlayerById(tos[1])
        local id = to:drawCards(1, self.name)[1]
        if room:getCardOwner(id) == to and room:getCardArea(id) == Card.PlayerHand then
          local card = Fk:getCardById(id)
          if (card.type == Card.TypeEquip or card.sub_type == Card.SubtypeDelayedTrick) and not to:prohibitUse(card) and to:canUse(card) then
            local use = room:askForUseCard(to, card.name, ".|.|.|.|.|.|"..tostring(id), "#ev__shenyin-invoke:::"..card:toLogString(), true)
            if use then
              room:useCard(use)
            end
          end
        end
      end
    end
  end,
}

local ev__jingjie = fk.CreateTriggerSkill{
  name = "ev__jingjie",
  anim_type = "control",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local room = player.room
      local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
      local end_id = turn_event.id
      return #U.getEventsByRule(room, GameEvent.MoveCards, 1, function (e)
        for _, move in ipairs(e.data) do
          if move.from ~= nil and move.from == player.id and (move.to ~= player.id or (move.toArea ~= Card.PlayerHand and move.toArea ~= Card.PlayerEquip)) then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                return true
              end
            end
          end
        end
        return false
      end, end_id) > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askForChoice(player, {"top", "bottom"}, self.name)
    local cards = room:getNCards(2, choice)
    --room:askForGuanxing(player, cards, {1, 1}, {1, 1})
    local get = U.askforChooseCardsAndChoice(player, cards, {"OK"}, self.name, "请选择置于牌堆另一端的牌")
    if #get > 0 then
      table.removeOne(cards, get[1])
      local to_top, to_bottom
      if choice == "top" then
        to_top = cards
        to_bottom = get
      else
        to_top = get
        to_bottom = cards
      end
      local move1 = {
        ids = to_top,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonPut,
        skillName = self.name,
      }
      local move2 = {
        ids = to_bottom,
        toArea = Card.DrawPile,
        moveReason = fk.ReasonPut,
        skillName = self.name,
        drawPilePosition = -1,
      }
      room:moveCards(move1, move2)
    end
    if player:isKongcheng() then
      choice = room:askForChoice(player, {"top", "bottom"}, self.name)
      player:drawCards(1, self.name, choice)
    end
  end,
}

Yukari:addSkill(ev__shenyin)
Yukari:addSkill(ev__jingjie)

Fk:loadTranslationTable{
  ["com__yukari"] = "八云紫",
  ["designer:com__yukari"] = "夜之礼赞",
  ["ev__shenyin"] = "神隐",
  [":ev__shenyin"] = "回合技（始），你可弃置X张牌（若X为0则不弃）并选择一项：1.将场上的一张牌置于牌堆底；2.令一名角色摸一张牌，若此牌为装备牌或延时魔法牌，其可使用之（X为你于本轮内发动过此技能的次数）。",
  ["#ev__shenyin-throw"] = "神隐：你可弃置%arg张牌",
  ["#ev__shenyin-choose"] = "神隐：你可将场上的一张牌置于牌堆底，或选择取消令一名角色摸一张牌",
  ["#ev__shenyin-draw"] = "神隐：请选择摸牌的角色",
  ["#ev__shenyin-invoke"] = "神隐：你可以使用%arg",
  ["ev__jingjie"] = "境界",
  [":ev__jingjie"] = "回合技（终），若你于当前回合内失去过牌，你可观看牌堆顶或底的两张牌，将其中的一张牌置于牌堆的另一端。然后若你没有手牌，你从牌堆顶或底摸一张牌。",
}

local Shiro = General(extension, "com__shiro", "com", 3, 3, General.Bigender)

local ev__tuiyan = fk.CreateTriggerSkill{
  name = "ev__tuiyan",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if player ~= target or not player:hasSkill(self) or player:usedSkillTimes(self.name) >= 2 then return false end
    local room = player.room
    local logic = room.logic
    local use_event = logic:getCurrentEvent()
    local events = logic.event_recorder[GameEvent.UseCard] or Util.DummyTable
    local last_find = false
    for i = #events, 1, -1 do
      local e = events[i]
      if e.data[1].from == player.id then
        if e.id == use_event.id then
          last_find = true
        elseif last_find then
          local last_use = e.data[1]
          return math.abs(data.card.number - last_use.card.number) == player.hp
           or math.abs(data.card.number - last_use.card.number) == player:getHandcardNum()
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.hp == player:getHandcardNum() then
      player:drawCards(2, self.name)
    else
      player:drawCards(1, self.name)
    end
  end,

  refresh_events = {fk.AfterCardUseDeclared, fk.EventLoseSkill},
  can_refresh = function(self, event, target, player, data)
    if event == fk.AfterCardUseDeclared then
      return target == player and player:hasSkill(self, true)
    elseif event == fk.EventLoseSkill then
      return target == player and data == self
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardUseDeclared then
      room:setPlayerMark(player, "@ev__tuiyan", {data.card.number})
    elseif event == fk.EventLoseSkill then
      room:setPlayerMark(player, "@ev__tuiyan", 0)
    end
  end,
}

function tablesEqual(table1, table2)--检测两个表是否元素相等
  -- 检查table1中的每个值是否在table2中有相等的
  for _, value in pairs(table1) do
      if not table.contains(table2, value) then
          return false
      end
  end
  -- 检查table2中的每个值是否在table1中有相等的
  for _, value in pairs(table2) do
      if not table.contains(table1, value) then
          return false
      end
  end
  return true
end

local ev__zhangkong = fk.CreateTriggerSkill{
  name = "ev__zhangkong",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name) < 2 then
      for _, move in ipairs(data) do
        if move.to == player.id and move.toArea == Player.Hand and move.skillName ~= self.name then
          return true
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, move in ipairs(data) do
      local n = #move.moveInfo
      local cards = player:drawCards(n, self.name)
      local puts = room:askForCard(player, n, n, true, self.name, false, ".", "#ev__zhangkong:::"..n)
      if tablesEqual(cards, puts) then
        local to_throw = room:askForCardsChosen(player, player, 0, n, {
          card_data = {
            { self.name, puts }
          }
        }, self.name, "#ev__mizang-throw")
        if #to_throw > 0 then
          for _, id in ipairs(to_throw) do
            table.removeOne(puts, id)
          end
          room:moveCardTo(to_throw, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, "", true)
        end
      end
      if #puts > 0 then
      room:moveCardTo(puts, Card.DrawPile, nil, fk.ReasonPut, self.name, "", true)
        if #puts > 1 then
          room:askForGuanxing(player, room:getNCards(#puts), {#puts, #puts}, {0, 0})
        end
      end
    end
  end,
}

Shiro:addSkill(ev__tuiyan)
Shiro:addSkill(ev__zhangkong)
Fk:loadTranslationTable{
  ["com__shiro"] = "空白",
  ["designer:com__shiro"] = "辰木&KINGDOM43",
  ["ev__tuiyan"] = "推演",
  [":ev__tuiyan"] = "回合技（2），当你使用牌时，若此牌与你使用的上一张牌的点数之差为你的手牌数或体力值，则你可摸一张牌；若你的手牌数与体力值相等，则你改为摸两张牌。",
  ["@ev__tuiyan"] = "推演",
  ["ev__zhangkong"] = "掌控",
  [":ev__zhangkong"] = "回合技（2），当你不因此技能获得牌后，你可摸等量的牌，然后将等量的牌置于牌堆顶；若你将以此法摸的牌均置于牌堆顶，则你将其中的任意张牌置入弃牌堆。",
  ["#ev__zhangkong"] = "掌控：请将%arg张牌置于牌堆顶",
}


local gemini = General(extension, "com__gemini", "com", 3, 3, General.Bigender)

local ev__jingzhongyin = fk.CreateTriggerSkill{
  name = "ev__jingzhongyin",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      local room = player.room
      if event == fk.CardUsing then
        local reds = room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e)
          local use = e.data[1]
          return use.from == player.id and use.card.color == Card.Red end, Player.HistoryTurn)
        local blacks = room.logic:getEventsOfScope(GameEvent.UseCard, 2, function(e)
          local use = e.data[1]
          return use.from == player.id and use.card.color == Card.Black end, Player.HistoryTurn)
        if data.card.color == Card.Red then
          return #reds == 1 and #blacks > 0
        elseif data.card.color == Card.Black then
          return #blacks == 1 and #reds > 0
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, self.name)
  end,
}

local ev__niliuyin = fk.CreateTriggerSkill{
  name = "ev__niliuyin",
  events = {fk.TargetConfirmed},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and not player.room:getPlayerById(data.from):isKongcheng()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.from)
    local cards = room:askForCardsChosen(player, to, 1, math.min(to:getHandcardNum(), 2), "h", self.name)
    room:moveCardTo(cards, Player.Hand, player, fk.ReasonPrey, self.name, nil, false, player.id)
    if not player.dead and not (to.dead or player:isNude()) then
      local n = math.min(#cards, #player:getCardIds("he"))
      local cards2 = room:askForCard(player, n, n, true, self.name, false, ".", "#ev__niliuyin::"..data.from..":"..n)
      room:moveCardTo(cards2, Player.Hand, to, fk.ReasonGive, self.name, nil, false, data.from)
    end
  end,
}

gemini:addSkill(ev__jingzhongyin)
gemini:addSkill(ev__niliuyin)

Fk:loadTranslationTable{
  ["com__gemini"] = "镜音双子",
  ["designer:com__gemini"] = "神域+辰木",
  ["ev__jingzhongyin"] = "镜中之音",
  [":ev__jingzhongyin"] = "当你于当前回合内首次使用<font color=\"#6495ED\">红色</font>/<font color=\"#D2042D\">黑色</font>牌时，若你于此回合内使用过<font color=\"#6495ED\">黑色</font>/<font color=\"#D2042D\">红色</font>牌，你可摸两张牌。",
  ["ev__niliuyin"] = "逆流之音",
  [":ev__niliuyin"] = "当你成为【杀】的目标后，你可获得此【杀】的使用者至多两张手牌，然后将等量的牌交给其。",
  ["#ev__niliuyin"] = "请将 %arg 张牌交给 %dest",
}

local Hajime = General(extension, "com__hajime", "com", 4)

local ev__yatuci = fk.CreateTriggerSkill{
  name = "ev__yatuci",
  events = {fk.EventPhaseStart, fk.TargetSpecified, fk.DamageCaused},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Play
    elseif event == fk.TargetSpecified or event == fk.DamageCaused then
      if target == player and player:getMark("yatuci_slash-turn") > 0 then
        if event == fk.TargetSpecified then
          return data.card.trueName == "slash"
        else
          return data.card and data.card.trueName == "slash" and not data.chain
          and table.find(data.to:getCardIds("hej"), function(id) return Fk:getCardById(id).color == Card.Black end)
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local choice = room:askForChoice(player, {"yatuci_slash", "yatuci_max"}, self.name)
      room:setPlayerMark(player, choice.."-turn", 1)
      if choice == "yatuci_max" then
        room:addPlayerMark(player, "AddMaxCards-turn", 2)
      end
    elseif event == fk.TargetSpecified then
      data.disresponsive = true
    elseif event == fk.DamageCaused then
      data.damage = data.damage + 1
    end
  end,
}

local yatuci_effect = fk.CreateProhibitSkill{
  name = "#yatuci_effect",
  prohibit_use = function(self, player, card)
    return player:getMark("yatuci_max-turn") > 0 and card.trueName == "slash"
  end,
}

ev__yatuci:addRelatedSkill(yatuci_effect)
Hajime:addSkill(ev__yatuci)

Fk:loadTranslationTable{
  ["com__hajime"] = "斋藤一",
  ["designer:com__hajime"] = "随风",
  ["ev__yatuci"] = "牙突刺",
  [":ev__yatuci"] = "锁定技，出牌阶段开始时，你选择并于本回合内获得一项效果：<br />1.当你使用【杀】指定一个目标后，你令此【杀】不是【闪】的合法目标，若其区域里有黑色牌，此【杀】对其造成的伤害+1；<br />2.你不能使用【杀】，且你的手牌上限+2。",
  ["yatuci_slash"] = "杀不能响应，目标有黑色牌加伤",
  ["yatuci_max"] = "不能使用杀，手牌上限+2",
  ["#yatuci_effect"] = "牙突刺",
}

SakaiYuuji = General(extension, "com__sakaiYuuji", "com", 3)

local grammatica = fk.CreateViewAsSkill{
  name = "Grammatica",
  pattern = "nullification,jink",
  interaction = function()
    local names = {}
    for _, name in ipairs({"ev__jink","ev__nullification"}) do
      local card = Fk:cloneCard(name)
      if (Fk.currentResponsePattern == nil and Self:canUse(card)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card)) then
        table.insertIfNeed(names, card.name)
      end
    end
    if #names == 0 then return end
    return U.CardNameBox {choices = names}
  end,
  card_filter = Util.TrueFunc,
  view_as = function(self, cards)
    local num = math.max(#Self:getCardIds("he") // 2, 1)
    if #cards ~= num or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    card:addSubcards(cards)
    return card
  end,

  enabled_at_play = Util.FalseFunc,
  enabled_at_response = function(self, player, response)
    return not response and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
}

local ev__lingshimizi = fk.CreateTriggerSkill{
  name = "ev__lingshimizi",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events ={fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Start and player:getHandcardNum() < player.maxHp
  end,

  on_use = function(self, event, target, player, data)
    local n = player.maxHp - player:getHandcardNum()
    player:drawCards(n, self.name)
  end,
}

SakaiYuuji:addSkill(grammatica)
SakaiYuuji:addSkill(ev__lingshimizi)

Fk:loadTranslationTable{
  ["com__sakaiYuuji"] = "坂井悠二",
  ["designer:com__sakaiYuuji"] = "亚里亚",
  ["Grammatica"] = "语法",
  [":Grammatica"] = "回合技，你可将X张牌当【闪】或【魔法禁令】使用（X为你的牌数的一半且至少为1）。",
  ["ev__lingshimizi"] = "零时迷子",
  [":ev__lingshimizi"] = "锁定技，准备阶段，你将手牌补至体力上限。",
}

local celestia = General(extension, "com__celestia", "com", 3, 3, General.Female)

local ev__duzheng = fk.CreateActiveSkill{
  name = "ev__duzheng",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, _, _, _, player)
    return #selected == 0 and to_select ~= player.id and player:canPindian(Fk:currentRoom():getPlayerById(to_select))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local pindian = player:pindian({target}, self.name)
    local winner = nil
    if pindian.results[target.id].winner == player then
      winner = player
    elseif pindian.results[target.id].winner == target then
      winner = target
    end
    if player.dead then return end
    local cards = {pindian.fromCard:getEffectiveId(), pindian.results[target.id].toCard:getEffectiveId()}
    if winner ~= nil then
      room:moveCardTo(cards, Card.PlayerHand, winner, fk.ReasonJustMove, self.name, "", true)
      --room:moveCardTo(pindian.results[target.id].toCard, Card.PlayerHand, winner, fk.ReasonJustMove, self.name, "", true)
      U.askForUseRealCard(room, winner, cards, ".", self.name, "#ev__duzheng-use")
    end
  end,
}

local ev__zhaqi = fk.CreateTriggerSkill{
  name = "ev__zhaqi",
  mute = true,
  anim_type = "control",
  events = {fk.StartPindian, fk.PindianCardsDisplayed},
  can_trigger = function(self, event, target, player, data)
    if event == fk.StartPindian then
      return player:hasSkill(self) and #data.tos == 1
    else
      return player:hasSkill(self) and player:getMark("zhaqi_buff") > 0
    end
  end,
  on_cost = Util.TrueFunc,  
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.StartPindian then
      if room:askForSkillInvoke(player, self.name) then
        room:setPlayerMark(player, "zhaqi_buff", 1)
      end
    else
      room:notifySkillInvoked(player, self.name)
      local fromcard = data.fromCard
      local tocard = data.results[data.tos[1].id].toCard
      local pindianCard = tocard
      local pindiantoCard = fromcard
      data.fromCard = pindianCard
      data.results[data.tos[1].id].toCard = pindiantoCard
      room:sendLog{
        type = "#ZhaqiReplace",
        from = data.from.id,
        to = {data.tos[1].id},
        arg = pindianCard:toLogString(),
        arg2 = pindiantoCard:toLogString()
      }
    end
  end,

  refresh_events = {fk.PindianResultConfirmed},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self) and player:getMark("zhaqi_buff") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "zhaqi_buff", 0)
    if data.winner and EV.isFriend(player, data.winner) then
      player:drawCards(1, self.name)
    end
  end,
}

celestia:addSkill(ev__duzheng)
celestia:addSkill(ev__zhaqi)

Fk:loadTranslationTable{
  ["com__celestia"] = "塞蕾丝缇雅",
  ["designer:com__sakaiYuuji"] = "亚里亚&zengyouyu",
  ["ev__duzheng"] = "赌争",
  [":ev__duzheng"] = "出牌阶段限一次，你可与一名其他角色拼点，然后拼点赢的角色获得双方拼点的牌，且可使用其中的一张牌。",
  ["#ev__duzheng-use"] = "赌争：你可使用其中的一张牌",
  ["ev__zhaqi"] = "诈欺",
  [":ev__zhaqi"] = "当两名角色拼点的牌亮出前，你可交换双方拼点的牌；然后若己方角色拼点赢，你摸一张牌。",
  ["#ZhaqiReplace"] = "%from 的拼点牌变为 %arg，%to 的拼点牌变为 %arg2",
}

local Hakurei = General(extension, "com__hakurei", "com", 3, 3, General.Female)

local ev__mengfeng = fk.CreateTriggerSkill{
  name = "ev__mengfeng",
  anim_type = "control",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local room = player.room
      local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
      local end_id = turn_event.id
      return #U.getEventsByRule(room, GameEvent.MoveCards, 1, function (e)
        for _, move in ipairs(e.data) do
          if move.from and move.from == player.id and move.moveReason == fk.ReasonDiscard then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                return true
              end
            end
          end
        end
        return false
      end, end_id) > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#ev__mengfeng", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end 
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    local types = {"basic", "trick", "equip"}
    local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
    local end_id = turn_event.id
    U.getEventsByRule(room, GameEvent.MoveCards, 999, function (e)
      for _, move in ipairs(e.data) do
        if move.from and move.from == player.id and move.moveReason == fk.ReasonDiscard then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              table.removeOne(types, Fk:getCardById(info.cardId):getTypeString())
            end
          end
        end
      end
      return false
    end, end_id)
    if #types == 0 or #room:askForDiscard(to, 1, 1, true, self.name, true, ".|.|.|.|.|"..table.concat(types, ","), "#ev__mengfeng-discard") == 0 then
      room:damage({
        from = player,
        to = to,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end,
}

local ev__kongfei = fk.CreateTriggerSkill{
  name = "ev__kongfei",
  events = {fk.TargetConfirming},
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = function(self, event, target, player, data)
    local suits = {"heart","spade","club","diamond"}
    if data.card.color == Card.Red then
      table.removeOne(suits, "heart")
      table.removeOne(suits, "diamond")
    elseif data.card.color == Card.Black then
      table.removeOne(suits, "spade")
      table.removeOne(suits, "club")
    end
    local card = player.room:askForDiscard(player, 1, 1, false, self.name, true, ".|.|"..table.concat(suits, ","), "#ev__kongfei-discard:::"..data.card:toLogString())
    return #card > 0
  end,
  on_use = function(self, event, target, player, data)
    AimGroup:cancelTarget(data, player.id)
    local colors = {}
    local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
    local end_id = turn_event.id
    U.getEventsByRule(player.room, GameEvent.MoveCards, 999, function (e)
      for _, move in ipairs(e.data) do
        if move.from and move.from == player.id and (move.to == nil or move.to ~= player.id) then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              table.insertIfNeed(colors, Fk:getCardById(info.cardId):getColorString())
            end
          end
        end
      end
      return false
    end, end_id)
    if #colors == 2 then
      player:drawCards(1, self.name)
    end
  end,
}

local ev__tiansheng = fk.CreateTriggerSkill{
  name = "ev__tiansheng",
  anim_type = "drawcard",
  frequency = Skill.Limited,
  events ={fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Finish and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local n = #table.filter(room.players, function (p) return p.dead end)
    local o = #room:getOtherPlayers(player)
    return room:askForSkillInvoke(player, self.name, nil, "#ev__tiansheng-invoke:::"..n..":"..o)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = #table.filter(room.players, function (p) return p.dead end)
    --if #room.players < 5 then n = n + 2 end
    player:drawCards(n, self.name)
    room:askForDiscard(player, #room:getOtherPlayers(player), #room:getOtherPlayers(player), true, self.name, false)
  end,
}

Hakurei:addSkill(ev__mengfeng)
Hakurei:addSkill(ev__kongfei)
Hakurei:addSkill(ev__tiansheng)

Fk:loadTranslationTable{
  ["com__hakurei"] = "博丽灵梦",
  ["designer:com__hakurei"] = "夜之礼赞",
  ["ev__mengfeng"] = "梦封",
  [":ev__mengfeng"] = "一名角色的回合结束时，若你于此回合内因弃置而失去过牌，你可令一名角色选择一项：1.弃置一张与这些牌类别均不同的牌；2.受到你造成的1点伤害。",
  ["#ev__mengfeng"] = "梦封：请选择一名角色",
  ["#ev__mengfeng-discard"] = "梦封：请选择弃置的牌，否则受到1点伤害",
  ["ev__kongfei"] = "空飞",
  [":ev__kongfei"] = "当你成为牌的目标时，你可弃置一张与此牌颜色不同的手牌，取消你自己；然后若你于当前回合内失去过两种颜色的牌，你摸一张牌。",
  ["#ev__kongfei-discard"] = "空飞：你可弃置一张与%arg颜色不同的手牌，取消你自己",
  ["ev__tiansheng"] = "天生",
  [":ev__tiansheng"] = "限定技，结束阶段，你可摸等同于死亡角色数的牌，然后弃置等同于其他角色数的牌。",--<font color=\"#D2042D\">若游戏人数小于5，额外摸两张牌。</font>
  ["#ev__tiansheng-invoke"] = "天生：<font color=\"#FFC0CB\">你可以摸%arg张牌</font>，<font color=\"#FFF5EE\">然后弃置%arg2张牌</font>",
}

local Kano = General(extension, "com__kano", "com", 3)

local ev__muqi = fk.CreateTriggerSkill{
  name = "ev__muqi",
  mute = true,
  events ={fk.TargetSpecified, fk.TargetConfirmed, fk.StartPindian},
  can_trigger = function(self, event, target, player, data)
    if event == fk.StartPindian then
      return player:hasSkill(self) and data.reason == self.name and (player == data.from or table.contains(data.tos, player))
      and player.phase == Player.NotActive
    else
      if target == player and player:hasSkill(self) and player:getMark("@@ev__muqi-turn") == 0 and not player:isKongcheng() then
        if event == fk.TargetSpecified then
          return data.to ~= player.id and U.isOnlyTarget(player.room:getPlayerById(data.to), data, event) and not player.room:getPlayerById(data.to):isKongcheng()
        else
          return data.from ~= player.id and U.isOnlyTarget(player, data, event) and not player.room:getPlayerById(data.from):isKongcheng()
        end
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local prompt
    if event == fk.TargetSpecified then
      prompt = "ev__muqi1-invoke::"..data.to
    elseif event == fk.TargetConfirmed then
      prompt = "ev__muqi2-invoke::"..data.from..":"..data.card:toLogString()
    else
      prompt = "#ev__muqi-invoke"
    end
    return player.room:askForSkillInvoke(player, self.name, nil, prompt)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    --player:broadcastSkillInvoke(self.name)
    if event == fk.TargetSpecified then
      room:notifySkillInvoked(player, self.name, "offensive")
      room:doIndicate(player.id, {data.to})
      local pindian = player:pindian({room:getPlayerById(data.to)}, self.name)
      if pindian.results[data.to].winner == player then
        room:askForDiscard(room:getPlayerById(data.to), 1, 1, true, self.name, false)
      else
        room:addPlayerMark(player, "@@ev__muqi-turn")
      end
    elseif event == fk.TargetConfirmed then
      room:notifySkillInvoked(player, self.name, "defensive")
      room:doIndicate(player.id, {data.from})
      local pindian = player:pindian({room:getPlayerById(data.from)}, self.name)
      if pindian.results[data.from].winner == player then
        table.insertIfNeed(data.nullifiedTargets, player.id)
      else
        room:addPlayerMark(player, "@@ev__muqi-turn")
      end
    else
      room:notifySkillInvoked(player, self.name, "special")
      if player == data.from then
        data.fromCard = Fk:getCardById(player.room.draw_pile[1])
      else
        data.results[player.id] = data.results[player.id] or {}
        data.results[player.id].toCard = Fk:getCardById(player.room.draw_pile[1])
      end
    end
  end,
}

Kano:addSkill(ev__muqi)

Fk:loadTranslationTable{
  ["com__kano"] = "鹿野修哉",
  ["designer:com__kano"] = "小妖辰末",
  ["ev__muqi"] = "目欺",
  [":ev__muqi"] = "当你指定/成为牌的唯一目标后，你可与此牌的目标/使用者拼点；若此时不在你的回合内，你可改为用牌堆顶的一张牌进行拼点。若你赢，你可令其弃置一张牌/令此牌无效；若你没赢，此技能于当前回合内失效。",
  ["@@ev__muqi-turn"] = "目欺失效",
  ["ev__muqi1-invoke"] = "目欺：你可以与 %dest 拼点，若赢，其弃置一张牌",
  ["ev__muqi2-invoke"] = "目欺：你可以与 %dest 拼点，若赢，此%arg对你无效",
  ["#ev__muqi-invoke"] = "目欺：是否用牌堆顶牌拼点？",
}

local tianzhaoyao = General(extension, "com__tianzhaoyao", "com", 4)
local ev__lingyin = fk.CreateActiveSkill{
  name = "ev__lingyin",
  anim_type = "support",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, _, _, _, player)
    return #selected == 0 and to_select ~= player.id and player.hp >= Fk:currentRoom():getPlayerById(to_select).hp
  end,
  on_use = function(self, room, effect)
    local target = room:getPlayerById(effect.tos[1])
    target:drawCards(1, self.name)
    if target:isWounded() then
      room:recover({
        who = target,
        num = 1,
        recoverBy = room:getPlayerById(effect.from),
        skillName = self.name
      })
    end
    local mark = target:getTableMark("ev__lingyin")
    table.insertIfNeed(mark, effect.from)
    room:setPlayerMark(target, "ev__lingyin", mark)
    room:addPlayerMark(target, "@@ev__lingyin")
  end,
}


local lingyin_distance = fk.CreateDistanceSkill{
  name = "#ev__lingyin_distance",
  frequency = Skill.Compulsory,
  fixed_func = function(self, from, to)
    if to:getMark("@@ev__lingyin") > 0 and from ~= to then
      return 1
    end
  end,
}

local lingyin_trigger = fk.CreateTriggerSkill{
  name = "#ev__lingyin_trigger",
  mute = true,
  refresh_events = {fk.TurnStart, fk.Deathed},
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(self, true, true) and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getOtherPlayers(player)) do
      local mark = p:getTableMark("ev__lingyin")
      if table.contains(mark, player.id) then
        table.removeOne(mark, player.id)
        if #mark == 0 then
          room:setPlayerMark(p, "@@ev__lingyin", 0)
        end
        room:setPlayerMark(p, "ev__lingyin", mark)
      end
      room:setPlayerMark(p, "@@ev__lingyin", 0)
    end
  end,
}

ev__lingyin:addRelatedSkill(lingyin_distance)
ev__lingyin:addRelatedSkill(lingyin_trigger)
tianzhaoyao:addSkill(ev__lingyin)

Fk:loadTranslationTable{
  ["com__tianzhaoyao"] = "田沼要",
  ["designer:com__tianzhaoyao"] = "无限连的陆伯言",
  ["ev__lingyin"] = "灵音",
  [":ev__lingyin"] = "回合技，你可令一名体力值不大于你的其他角色摸一张牌，回复1点体力；然后直至你的下回合开始，除其外的角色与其的距离视为1。",
  ["@@ev__lingyin"] = "灵音",
}

return extension